package Student;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s1 = new Scanner(System.in);
        ClassManager c1 = new ClassManager();
        GroupManager g2 = new GroupManager();
        StudentManager s2 = new StudentManager();
        RandomSelector r1 = new RandomSelector(c1, g2, s2);

        c1.addClass("一班");
        c1.addClass("二班");
        c1.addClass("三班");

        g2.addGroup("第一小组", "一班");
        g2.addGroup("第三小组", "二班");
        g2.addGroup("第一小组", "三班");
        g2.addGroup("第二小组", "一班");

        s2.addStudent("小天", "一班");
        s2.addStudent("小刘", "三班");
        s2.addStudent("小琪", "三班");
        s2.addStudent("小王", "二班");
        s2.addStudent("阿浩", "一班");
        s2.addStudent("柒柒", "二班");

        while (true) {
            System.out.println("班级管理系统");
            System.out.println("1. 班级管理");
            System.out.println("2. 小组管理");
            System.out.println("3. 学生管理");
            System.out.println("4. 随机点名");
            System.out.println("5. 退出");
            System.out.print("请选择操作: ");
            int choice = s1.nextInt();
            s1.nextLine();  // 清除换行符

            switch (choice) {
                case 1:
                    manageClasses(s1, c1);
                    break;
                case 2:
                    manageGroups(s1, g2);
                    break;
                case 3:
                    manageStudents(s1, s2);
                    break;
                case 4:
                    randomSelection(s1, r1);
                    break;
                case 5:
                    System.out.println("退出系统");
                    s1.close();
                    return;
                default:
                    System.out.println("无效选项");
            }
        }
    }

    private static void manageClasses(Scanner scanner, ClassManager classManager) {
        System.out.println("班级管理");
        System.out.println("1. 新增班级");
        System.out.println("2. 查看班级列表");
        System.out.print("请选择操作: ");
        int choice = scanner.nextInt();
        scanner.nextLine();  // 清除换行符

        switch (choice) {
            case 1:
                System.out.print("请输入班级名称: ");
                String className = scanner.nextLine();
                classManager.addClass(className);
                break;
            case 2:
                System.out.println("班级列表: " + classManager.getClasses());
                break;
            default:
                System.out.println("无效选项");
        }
    }

    private static void manageGroups(Scanner scanner, GroupManager groupManager) {
        System.out.println("小组管理");
        System.out.println("1. 新增小组");
        System.out.println("2. 查看小组列表");
        System.out.print("请选择操作: ");
        int choice = scanner.nextInt();
        scanner.nextLine();  // 清除换行符

        switch (choice) {
            case 1:
                System.out.print("请输入小组名称: ");
                String groupName = scanner.nextLine();
                System.out.print("请输入班级名称: ");
                String className = scanner.nextLine();
                groupManager.addGroup(groupName, className);
                break;
            case 2:
                System.out.println("小组列表: " + groupManager.getGroups());
                break;
            default:
                System.out.println("无效选项");
        }
    }

    private static void manageStudents(Scanner scanner, StudentManager studentManager) {
        System.out.println("学生管理");
        System.out.println("1. 新增学生");
        System.out.println("2. 查看学生列表");
        System.out.print("请选择操作: ");
        int choice = scanner.nextInt();
        scanner.nextLine();  // 清除换行符

        switch (choice) {
            case 1:
                System.out.print("请输入学生姓名: ");
                String studentName = scanner.nextLine();
                System.out.print("请输入班级名称: ");
                String className = scanner.nextLine();
                studentManager.addStudent(studentName, className);
                break;
            case 2:
                System.out.println("学生列表: " + studentManager.getStudents());
                break;
            default:
                System.out.println("无效选项");
        }
    }

    private static void randomSelection(Scanner scanner, RandomSelector randomSelector) {
        System.out.println("随机点名");
        System.out.print("1. 随机抽取小组\n2. 随机抽取班级学生\n请选择操作: ");
        int choice = scanner.nextInt();
        scanner.nextLine();  // 清除换行符

        switch (choice) {
            case 1:
                String randomGroup = randomSelector.selectRandomGroup();
                System.out.println("随机抽取的小组: " + randomGroup);
                break;
            case 2:
                System.out.print("请输入班级名称: ");
                String className = scanner.nextLine();
                String randomStudent = randomSelector.selectRandomStudent(className);
                System.out.println("随机抽取的学生: " + randomStudent);
                break;
            default:
                System.out.println("无效选项");
        }
    }
}